import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class CallStruct {
    public static void main(String[] args) {
        try {
            Class<?> rectangleClass = Class.forName("Rectangle");

            Constructor<?> declaredConstructor = rectangleClass.getDeclaredConstructor(double.class, double.class);
            Object instance = declaredConstructor.newInstance(12, 23);

            Method getArea = rectangleClass.getMethod("getArea");
            Object invoke = getArea.invoke(instance);
            System.out.println(invoke);

            Field width = rectangleClass.getDeclaredField("width");
            width.setAccessible(true);
            Object w = width.get(instance);
            System.out.println(w);

        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
